package com.roubsite.admin.dao.activiti;

import java.sql.Types;
import java.util.List;

import com.roubsite.database.dao.EntityDao;
import com.roubsite.utils.StringUtils;

public class ActivitiDao extends EntityDao implements IActivitiDao {

	@Override
	public List getUsers(String organ_id) {
		return this.query(
				"SELECT * FROM RS_USERS A LEFT JOIN RS_USERS_ORGAN B ON A.USER_ID=B.USER_ID WHERE B.ORGAN_ID=?",
				new String[] { organ_id }, new int[] { Types.VARCHAR });
	}

	@Override
	public List getAllOrgan() {
		return this.query("SELECT * FROM RS_ORGAN", null, null);
	}

	@Override
	public void saveActivitiExt(String modeId, String name, String filePath) {
		String time = StringUtils.getUnixDate();
		List list = this.query("SELECT * FROM RS_ACTIVITI_EXT WHERE ID=?", new String[] { modeId },
				new int[] { Types.VARCHAR });
		if (null != list && list.size() > 0) {
			this.excute("UPDATE RS_ACTIVITI_EXT SET NAME=?,ACTIVITI_XML_PATH=?,UPDATE_TIME=? WHERE ID = ?",
					new String[] { name, filePath, time, modeId },
					new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });
			return;
		}

		this.excute("INSERT INTO RS_ACTIVITI_EXT (ID,NAME,ACTIVITI_XML_PATH,CREATE_TIME,UPDATE_TIME) VALUES (?,?,?,?,?)",
				new String[] { modeId, name, filePath, time, time },
				new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });

	}

	@Override
	public void saveActivitiExtName(String id, String name) {
		String time = StringUtils.getUnixDate();
		this.excute("UPDATE RS_ACTIVITI_EXT SET NAME=?,UPDATE_TIME=? WHERE ID = ?", new String[] { name, time, id },
				new int[] { Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });
	}

}
